﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.Core.Metadata;
using Luna.WPF.ApplicationFramework;
using XWord.Fundamental.Domain.Model;
using Microsoft.Practices.ServiceLocation;
using XWord.Fundamental.Domain;
using System.Threading;
using XWord.WPF.ApplicationFramework;
using XWord.GUI.Presenters.Interface;
using XWord.Fundamental.Domain.Services;
using System.Windows.Threading;
using XWord.WPF.ApplicationFramework.Threads;
using XWord.Common;
using System.Collections.Specialized;
using System.Windows;
using XWord.Common.Extensions;

namespace XWord.GUI.Presenters.Fundamental
{
   public partial class WordTabPresenter
    {

        public void SearchEtyma(string text)
        {
            text = SearchText;

            _delayTimer.AddObj(SearchText);
        }

        private void DefaultSearch(object text)
        {
            Console.WriteLine(text);
            if (text == null || string.IsNullOrEmpty(text.ToString()))
                return;
            var cancel = WordBehavior.RaiseWordSearchEventHandler(SearchText);
            if (cancel) return;
            if (SearchMode > 0)
            {
                WordExplorerPresenter.SearchWord(SearchText);

                DockSitePresenter.Activate(WordExplorerPresenter);
            }
            else
            {
                EtymaLibraryExplorerPresenter.Search(SearchText.ToLower());
                DockSitePresenter.Activate(EtymaLibraryExplorerPresenter);
            }
        }

        public void SetSearchWord(object obj)
        {
            if (obj != null)
                SelectedAlphabet = obj as Alphabet;
            //if (text == null) return;
            //this.SearchText = text.ToString();
        }

        public void InternalSearchWord(string text)
        {
            WordExplorerPresenter.AdornerElement.Items.Filter = new Predicate<object>((object obj) =>
            {
                var word = obj.ToString();
                if (text.Length > 0)
                    return word.StartsWith(text);
                return true;
            });
        }

        public void SaveAlphabet(Alphabet bet)
        {
            //RemotingServiceFactory.GetWordService().SaveGenericFile(BinaryFiles.AlphabetList, AlphabetList.ToArray());
        }

    }
}
